import { ContentTypeEnum, createHttpClient } from './HttpClient';

interface LoginResponse {
  token: string;
}

const api = createHttpClient({
  baseUrl: 'https://aiedm.wchingtech.com/api/',
  headers: {
    'X-Client-Type': 'mobile',
  },
});
// 為了避免userStore內使用api循環依賴，增加token注入方法，登入成功後注入，登出要清空
export function setToken(token: string | null){
  api.setToken(token);
}

export function login(params: any) {
  return api.post<LoginResponse>('auth/login', {
    data: params,
    contentType: ContentTypeEnum.Json
  });
}

export { api };
